import { defineStore } from 'pinia'
import { store } from '@/stores'

export const useAppStore = defineStore({
  id: 'live-broadcast-app',
  state: () => ({
		appName: '',
		appInfo: [
			{ title: '登录账号', value: '' },
			{ title: 'APP名称', value: '' },
			{ title: '版本', value: '0.1.0' },
			{ title: '关于', value: '' },
		]
  }),
  actions: {
		SET_APPNAME(name) {
			this.appName = name
			this.appInfo[1].value = name || this.appName
		},
		SET_ACCOUNT(account) {
			this.appInfo[0].value = account
		},
		SET_LOGIN_DATA(loginFormData) {
			uni.setStorage({
				key: 'LOGIN_DATA',
				data: JSON.stringify(loginFormData),
			})
		},
		GET_LOGIN_DATA() {
		 return	new Promise((resolve, reject) => {
				uni.getStorage({
					key: 'LOGIN_DATA',
					success: (res) => {
						const getLogin = JSON.parse(res.data)
						resolve(getLogin)
					},
					fail: (e) => {
						reject(e)
					}
				});
			})
		},
		REMOVR_LOGIN_DATA() {
			uni.removeStorage({
				key: 'LOGIN_DATA',
				success: (res) => {}
			});
		}
  }
})

export function useAppStoreHook() {
  return useAppStore(store)
}
